/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package negocio;

import bancoDados.DAO;
import beans.SupermercadoBean;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Felipe Tadeu
 */
public class SupermercadoDAO extends DAO {

    public ArrayList<SupermercadoBean> buscarTodos() {

        ArrayList<SupermercadoBean> listaSupermercados = new ArrayList<SupermercadoBean>();

        try {

            String sql = "SELECT * FROM SUPERMERCADOS ORDER BY DSC_RAZAO_SOCIAL";
            PreparedStatement stmt = conn.prepareStatement(sql);
            ResultSet rs = stmt.executeQuery();

            while (rs.next()) {
                // Criando objetos     
                SupermercadoBean supermercados = new SupermercadoBean();
                supermercados.setCodSupermercado(rs.getInt("COD_SUPERMERCADO"));
                supermercados.setCodUsuario(rs.getInt("COD_USUARIO"));
                supermercados.setDscRazaoSocial(rs.getString("DSC_RAZAO_SOCIAL"));
                supermercados.setDscNomeFantasia(rs.getString("DSC_NOME_FANTASIA"));
                supermercados.setNumCnpj(rs.getInt("NUM_CNPJ"));
                supermercados.setDscEndereco(rs.getString("DSC_ENDERECO"));
                listaSupermercados.add(supermercados);
            }

            rs.close();
            stmt.close();

        } catch (SQLException ex) {
            Logger.getLogger(SupermercadoDAO.class.getName()).log(Level.SEVERE, null, ex);
        }

        return listaSupermercados;

    }

}
